<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 3, $gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
$g_betname_3or5 = judge_type($gametype);
$getShow35 = getShow35($gametype);
unset($chk);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
include( "class_3d/Amounts_3d.php" );
$ui = new UI_3D();
$conf = new Config();
$tpl = new Template2();
$user = new User();
$Amounts_3d = new Amounts_3d($gametype);
$curruser_p = user::getuser($curruser['id'], $gametype);
$editportmod = intval($conf->get("editportmod_{$tbl}"));
$autorate_mode = intval($conf->get("autoportmod_{$tbl}"));
$editmode = 0;
$psen_edit_mod = 1;
$lotto_id = 0;
$startbet = $conf->get("startbet_{$tbl}");
$stopbet = $conf->get("stopbet_{$tbl}");
switch ($show3D3S)
{
    case 0 :
        $rs = getdb("select id,open from lotto_{$tbl} where open>='" . date("Y-m-d") . "' order by open");
        if (!$rs->eof)
        {
            $lotto_id = $rs->f['id'];
            $open = $rs->f['open'];
            $rs->close();
            if (date("Y-m-d") == $open)
            {
                $stopbet = 2200;
                if ($startbet < date("Hi") && date("Hi") < $stopbet)
                {
                    $psen_edit_mod = $editportmod;
                }
            }
        }
        break;
    case 1 :
        $nextDateFlag = false;
        if ($stopbet < $startbet)
        {
            $nextDateFlag = true;
        }
        $now = date("Hi");
        $todayTime = systime();
        if ($nextDateFlag && $now < $stopbet)
        {
            $today = date("Y-m-d", strtotime("-1 day"));
        }
        else
        {
            $today = date("Y-m-d");
        }
        $rs = getdb("select open,id from lotto_{$tbl} where open>='{$today}' order by id ASC LIMIT 0,1");
        if (!$rs->eof)
        {
            $open = $rs->f['open'];
            $lotto_id = $rs->f['id'];
            $rs->close();
            if ($today == $open)
            {
                if ($nextDateFlag)
                {
                    $addMin = 86460;
                }
                else
                {
                    $addMin = 60;
                }
                $stoptime = $open . " " . substr($stopbet, 0, 2) . ":" . substr($stopbet, 2, 2) . ":00";
                $stopInt = strtotime($stoptime) + $addMin;
                $starttime = $open . " " . substr($startbet, 0, 2) . ":" . substr($startbet, 2, 2) . ":00";
                $startInt = strtotime($starttime);
                if ($startInt <= $todayTime && $todayTime <= $stopInt)
                {
                    $psen_edit_mod = $editportmod;
                }
            }
        }
        break;
}
$users = GetUserList($curruser['id']);
if ($users != "" && 0 < $lotto_id)
{
    $rs = getdb("select sum(amount) from bet_{$tbl} where user_id in ({$users}) and lotto_id>={$lotto_id} and rame=0");
    if ($rs->f[0] + 0 == 0)
    {
        $psen_edit_mod = 1;
    }
    else
    {
        $psen_edit_mod = 0;
    }
    $rs->close();
}
if (getvar("chgpasswd") != "")
{
    if ($user->ChangePassword(getvar("chgpasswd")) == false)
    {
        $tpl->set("msg", L_CHGPWDFAIL);
    }
    else
    {
        $tpl->set("msg", L_CHGPWDSUCC);
    }
}
$theacl = $curruser['acl'];
$tpl->load(array("main" => "info_3d.htm"));
$tpl->set("account", $curruser['account']);
$tpl->set("name", $curruser['name']);
$tpl->set("amount", number_format($curruser['amount']));
$percent = 1;
if ($theacl == 2)
{
    $percent = $curruser_p['mpercent'];
    $tpl->set("percent", "<tr><td class=\"title0 bgImg_{$gametype}\">占成<td class=td2>{$percent}%");
}
$protmod = 0;
if (0 < $autorate_mode)
{
    if ($theacl == 2)
    {
        $u_genagent = get_user($curruser['prev_id'], $gametype);
        $u_shareowner = get_user($u_genagent['prev_id'], $gametype);
        $u_subsidary = get_user($u_shareowner['prev_id'], $gametype);
        $protmod = $u_subsidary['protmod'];
    }
    else if ($theacl == 3)
    {
        $u_shareowner = get_user($curruser['prev_id'], $gametype);
        $u_subsidary = get_user($u_shareowner['prev_id'], $gametype);
        $protmod = $u_subsidary['protmod'];
    }
    else if ($theacl == 4)
    {
        $u_subsidary = get_user($curruser['prev_id'], $gametype);
        $protmod = $u_subsidary['protmod'];
    }
    else if ($curruser_p['percent_sw'] == 1)
    {
        $protmod = 0;
        $psen_edit_mod = 0;
    }
    else
    {
        $protmod = $curruser_p['protmod'];
    }
}
if (0 < $psen_edit_mod && 0 < $protmod && isset($_POST['auto_ok']))
{
    foreach ($g_betname_3or5 as $key => $value)
    {
        if (isset($_POST["autont" . $key]))
        {
            $auto_nt = intval($_POST["autont" . $key]);
            $auto_ntOld = intval($_POST["autont" . $key . "old"]);
            if ($auto_nt != $auto_ntOld)
            {
                $bettypeArr = explode("_", $key);
                $sql = "update amounts_{$tbl} set auto_nt=" . $auto_nt . " ,updateid=" . $curruser['id'] . " ,updatedt='" . date("Y-m-d H:i:s") . "' where user_id=" . $curruser['id'] . " and bettype=" . $bettypeArr[0] . " and subid=" . $bettypeArr[1] . "";
                getdb($sql);
            }
        }
    }
}
$list = "";
$rs = $Amounts_3d->getAmountsRsById($curruser['id']);
$chk_autont = 0;
$data=array();
$order=array(55=>0,0=>1,69=>2,70=>3,1=>4,2=>5,3=>6,56=>7,57=>7,58=>7,59=>8,60=>8,61=>8,4=>9,7=>9,10=>9,5=>10,8=>10,11=>10);
while (!$rs->eof)
{
	$item=$rs->f;
	$item['order']=(isset($order[$rs->f['bettype']])?$order[$rs->f['bettype']]:99);
	$data[]=$item;
	$rs->movenext();
}
$data=SortArray($data,"order");
foreach($data as $rs){
    if (isset($g_betname_3or5[$rs['bettype'] . "_" . $rs['subid']]))
    {
        $list .= "<tr class=\"td2\">";
        $list .= "<td nowrap class=\"td17\">" .$g_betname_3or5[$rs['bettype'] . "_" . $rs['subid']] . "</td>";
        if ($rs['amount2'] == 0)
        {
            $list .= "<td nowrap align=\"right\"> - </td>";
            $list .= "<td nowrap align=\"right\"> - </td>";
            $list .= "<td nowrap align=\"right\"> - </td>";
        }
        else
        {
            $list .= "<td nowrap align=\"right\">" . round(100 - $rs['back1'], 2) . "</td>";
            $list .= "<td nowrap align=\"right\">" . round(100 - $rs['back2'], 2) . "</td>";
            $list .= "<td nowrap align=\"right\">" . round(100 - $rs['back3'], 2) . "</td>";
            $list .= "<td nowrap align=\"right\">" . round(100 - $rs['back4'], 2) . "</td>";
            $list .= "<td nowrap align=\"right\">" . number_format($rs['amount2']) . "</td>";
            $list .= "<td nowrap align=\"right\">" . number_format($rs['amount1']) . "</td>";
            if (0 < $protmod)
            {
                if (0 < $psen_edit_mod)
                {
                    $list .= "<td nowrap align=\"right\"><input type=\"hidden\" value=\"" . $rs['auto_nt'] . "\" name=\"autont" . $rs['bettype'] . "_" . $rs['subid'] . "old\" size=\"6\" style=\"text-align:right\" /><input type=\"text\" value=\"" . $rs['auto_nt'] . "\" name=\"autont" . $rs['bettype'] . "_" . $rs['subid'] . "\" size=\"6\" style=\"text-align:right\" /></td>";
                }
                else
                {
                    $list .= "<td nowrap align=\"right\">" . $rs['auto_nt'] . "</td>";
                }
                $list .= "<td nowrap align=\"right\">" . $rs['updatedt'] . "</td>";
            }
        }
        $list .= "</tr>";
        ++$chk_autont;
    }
}
if ($list == "")
{
    $list = "<tr class=\"row1\"><td colspan=\"7\">查无资料</td></tr>";
}

if ($autorate_mode && 0 < $chk_autont && 0 < $protmod)
{
    $tpl->set("tableexc1", "<td class=\"title0 bgImg_{$gametype}\" width='14%'>自动走飞设定</td>");
    $tpl->set("tableexc2", "<td class=\"title0 bgImg_{$gametype}\" width='22%'>最後修改的日期 时间</td>");
    if (0 < $psen_edit_mod && $autorate_mode)
    {
        $tpl->set("rottexc", "<font color=red>※ 自动走飞金额为 0 代表该项目不启动自动走飞！</font>");
        $tpl->set("btnsubmit", "<input type=submit value=确定>");
        $list .= "<input type=hidden name=auto_ok value=1>";
    }
    else
    {
        $tpl->set("rottexc", "<font color=red>※ 开盘中禁止设置或变更自动走飞金额！</font>");
    }
}
$tpl->set("test", $test = $getShow35 ? "20" : "14");
$tpl->set("amountlist", $list);
$tpl->set("gametypeStr", $tblName);
$tpl->set("gametype", $gametype);
include( "class/class.Bnowconfig.php" );
$Bnowconfig = new Bnowconfig($gametype, $curruser['id']);
$showBnowArr = array("r1", "r2p", "r2", "r3p", "r3");
$showBnowArrStr = array("一字定位", "二字定位", "二字不定位", "三字定位", "三字不定位");
$alertArr = $Bnowconfig->getVal($showBnowArr);
$list = "";
foreach ($showBnowArr as $key => $val)
{
    $tempIdx = "bnow" . $val;
    if (isset($_POST[$tempIdx]) && intval($_POST[$tempIdx]) != $alertArr[$val])
    {
        $Bnowconfig->setVal($val, intval($_POST[$tempIdx]));
        $alertArr[$val] = intval($_POST[$tempIdx]);
    }
    $list .= "<tr><td class=\"title0 bgImg_{$gametype}\" align=right>" . $showBnowArrStr[$key] . "</td><td class=td2><input type=\"text\" name=\"{$tempIdx}\" value=\"" . $alertArr[$val] . "\" /></td></tr>";
}
$tpl->set("bnowlist", $list = $getShow35 ? "" : "{$list}");
$ui->header();
$ui->showNews3D($curruser['acl']);
$tpl->show("main");
$ui->footer();
echo "\r\n\r\n";
?>